<template>
	<view class="minh-bg">
		<fa-navbar title="审核列表"></fa-navbar>
		<view class="pos-fix fullwidth" style="z-index: 10;">
			<u-tabs :list="tabList" height="96" :is-scroll="false" font-size="28" bar-width="80" :current="current" @change="tabsChange"></u-tabs>
			<view class="cb px-2 py-m2 bg-ff">
				<view class="float-right flex-center" @click="showFilter = !showFilter">
					<u-image v-if="!showFilter" width="28" height="24" src="/static/images/shfilter01.svg"></u-image>
					<u-image v-else width="28" height="24" src="/static/images/shfilter02.svg"></u-image>
					<text class="pl-m1 font24" :style="{color: !showFilter ? '#666666' : '#2E73E5'}">筛选</text>
				</view>
			</view>
			<fa-filter-examine :area="areaList" :status="statusList" :showFilter="showFilter" :changeTab="changeTab" @funFilter="filterData" @funShow="showFilterModel" @funOpen="assignFilterDrop"></fa-filter-examine>
		</view>
		<view class="p-4"></view>
		<view class="p-2">
			<fa-examine-list :list="dataList" @methods="toPage"></fa-examine-list>
			<!-- 暂无数据 -->
			<view v-if="noData" class="text-center col-gray">没有数据</view>
			<!-- 分页加载 -->
			<u-loadmore v-if="showLoadmore" :status="loadStatus" margin-top="20" @loadmore="getExamineList"/>
		</view>
	</view>
</template>

<script>
	import faNavbar from '@/components/fa-navbar/fa-navbar.vue'
	import faExamineList from './components/fa-examine-list.vue'
	import faFilterExamine from './components/fa-filter-examine.vue'
	export default {
		components: {
			faNavbar,
			faExamineList,
			faFilterExamine
		},
		data() {
			return {
				tabList: [{name: '全部'}, {name: '待审核'}, {name: '审核通过'}, {name: '审核未通过'}],
				current: 0,
				formData: {
					HandleTypes: [],
					ApproveStates: [],
					OrgGuids: [],
					PageIndex: 1,
					PageSize: 15
				},
				dataList: [],
				areaList: [],
				statusList: [],
				showFilter: false,
				changeTab: 0,
				loadStatus: 'loading',
				showLoadmore: true,
				noData: false
			}
		},
		onLoad() {
			this.getOrgList();
			this.getExamineType();
		},
		onShow() {
			this.formData.PageIndex = 1;
			this.getExamineList();
		},
		onReachBottom() {
			// 分页加载
			this.loadStatus == 'nomore' ? null : this.getExamineList();
		},
		methods: {
			// tabs通知swiper切换
			tabsChange(index) {
				let types = [];
				this.current = index;
				this.showFilterModel(false);
				this.noData = false;
				// 页面类型赋值
				index == 1 ? types = ['ASSET_APPROVE_0001'] : index == 2 ? types = ['ASSET_APPROVE_0002'] : index == 3 ? types = ['ASSET_APPROVE_0003'] : [];
				// 切换页面时重置筛选数据
				this.changeTab = Math.random();
				// 设置参数获取数据
				this.formData.HandleTypes = [];
				this.formData.OrgGuids = [];
				this.formData.ApproveStates = types;
				this.formData.PageIndex = 1;
				this.$store.dispatch('scrollToTop');
				this.getExamineList();
			},
			
			// 获取列表数据
			getExamineList() {
				// 分页加载
				this.showLoadmore = true;
				this.loadStatus = 'loading';
				this.noData = false;
				this.$api.getExamineList(this.formData)
					.then( res => {
						if (res.code === 0) {
							if (this.formData.PageIndex > 1) {
								this.dataList = this.dataList.concat(res.data.Data);
							} else {
								this.dataList = res.data.Data;
							}
							// 分页加载-判断分页
							if (res.data.Page == res.data.TotalPage) {
								this.showLoadmore = false;
								this.loadStatus = 'nomore';
							} else {
								this.loadStatus = 'loadmore';
							}
							if (this.dataList.length == 0) {
								this.showLoadmore = false;
								this.noData = true;
							}else {
								this.noData = false;
							}
							this.formData.PageIndex  = this.formData.PageIndex + 1;
						} else {
							// 分页加载
							this.noData = false;
							this.showLoadmore = false;
							this.loadStatus = 'nomore';
						}
					})
					.catch(err => console.error(err))
			},
			
			// 获取房产筛选
			getOrgList() {
				let params = {
					OrgCode: "",
					OrgName: ""
				}
				this.$api.getOrgList(params)
					.then(res => {
						if (res.code == 0) {
							res.data.forEach(ele => {
								this.$set(ele, 'check', false)
							})
							this.areaList = res.data;
						}
					})
					.catch(err => console.error(err));
			},
			
			// 获取处置类型
			getExamineType() {
				let params = {
					LangCode: "zh-CN",
					SystemCode: "",
					ParentDictKey: "ASSET_HANDLE",
					DictType: "ITEM"
				}
				this.$api.getExamineType(params)
					.then(res => {
						if (res.code == 0) {
							res.data.forEach(ele => {
								this.$set(ele, 'check', false)
							})
							this.statusList = res.data;
						}
					})
					.catch(err => console.error(err));
			},
			
			// 筛选数据
			filterData(data) {
				this.$store.dispatch('scrollToTop');
				this.formData.OrgGuids = data.orgGuids;
				this.formData.HandleTypes = data.handleTypes;
				this.formData.PageIndex = 1;
				this.getExamineList();
			},
			
			// 打开下拉筛选时选中过的默认赋值
			assignFilterDrop(data) {
				this.areaList = JSON.parse(data.area);
				this.statusList = JSON.parse(data.status);
			},
			
			// 打开关闭filter
			showFilterModel(info) {
				this.showFilter = info
			},
			
			// 页面跳转
			toPage(data) {
				uni.navigateTo({
					url: `/pages/examine/detail?hGuid=${data.HandleGuid}`
				})
			}
		}
	}
</script>

<style>
</style>
